package cn.yunyichina.openapi.proxy.config;

import cn.yunyichina.utils.commons.StringUtils;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * HttpServer的配置
 *
 * @author zhangkewen
 */
public class HttpServerConfig {

    private static HttpServerConfig config;

    public static HttpServerConfig getConfig() {
        if (config == null) {
            config = new HttpServerConfig();
        }
        return config;
    }

    /* 是否采用ssl连接 */
    private boolean ssl;

    public boolean getSsl() {
        return ssl;
    }

    public void setSsl(boolean ssl) {
        this.ssl = ssl;
    }

    /* 监听端口 */
    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    private int port;

    /* 是否需要验证客户端的证书 */
    private boolean server_need_client_auth = false;

    public boolean getServer_need_client_auth() {
        return server_need_client_auth;
    }

    public void setServer_need_client_auth(boolean server_need_client_auth) {
        this.server_need_client_auth = server_need_client_auth;
    }

    /* 是否开启http长连接 */
    private boolean supportkeepalive;

    public boolean getSupportkeepalive() {
        return supportkeepalive;
    }

    public void setSupportkeepalive(boolean supportkeepalive) {
        this.supportkeepalive = supportkeepalive;
    }

    public String getZookeeperurl() {
        return zookeeperurl;
    }

    public void setZookeeperurl(String zookeeperurl) {
        this.zookeeperurl = zookeeperurl;
    }

    private String zookeeperurl;

    private String jdbcUrl;

    public String getJdbcUrl() {
        return jdbcUrl;
    }

    public void setJdbcUrl(String jdbcUrl) {
        this.jdbcUrl = jdbcUrl;
    }

    public String getJdbcDriverclass() {
        return jdbcDriverclass;
    }

    public void setJdbcDriverclass(String jdbcDriverclass) {
        this.jdbcDriverclass = jdbcDriverclass;
    }

    public String getJdbcUsername() {
        return jdbcUsername;
    }

    public void setJdbcUsername(String jdbcUsername) {
        this.jdbcUsername = jdbcUsername;
    }

    public String getJdbcPassword() {
        return jdbcPassword;
    }

    public void setJdbcPassword(String jdbcPassword) {
        this.jdbcPassword = jdbcPassword;
    }

    private String jdbcDriverclass;
    private String jdbcUsername;
    private String jdbcPassword;

    /**
     * ssl密码
     */
    private String sslPassword;

    public String getSslPassword() {
        return sslPassword;
    }

    public void setSslPassword(String sslPassword) {
        this.sslPassword = sslPassword;
    }

    /**
     * ssl证书路径
     */
    private String sslPath;

    public String getSslPath() {
        return sslPath;
    }

    public void setSslPath(String sslPath) {
        this.sslPath = sslPath;
    }


    /**
     * 脱敏需要的密钥
     */
    private String aesKey;

    public String getAesKey() {
        return aesKey;
    }

    public void setAesKey(String aesKey) {
        this.aesKey = aesKey;
    }

    /**
     * 手机需要脱敏的方法
     */
    private String mobileSensitiveMethod;

    private String idCardNoSensitiveMethod;

    private String bankCardNoSensitiveMethod;

    /**
     * 手机需要脱敏的appCode
     */
    private String mobileSensitiveAppCode;

    private String idCardNoSensitiveAppCode;

    private String bankCardNoSensitiveAppCode;

    public String getIdCardNoSensitiveMethod() {
        return idCardNoSensitiveMethod;
    }

    public void setIdCardNoSensitiveMethod(String idCardNoSensitiveMethod) {
        this.idCardNoSensitiveMethod = idCardNoSensitiveMethod;
    }

    public String getIdCardNoSensitiveAppCode() {
        return idCardNoSensitiveAppCode;
    }

    public void setIdCardNoSensitiveAppCode(String idCardNoSensitiveAppCode) {
        this.idCardNoSensitiveAppCode = idCardNoSensitiveAppCode;
    }

    public String getMobileSensitiveMethod() {
        return mobileSensitiveMethod;
    }

    public void setMobileSensitiveMethod(String mobileSensitiveMethod) {
        this.mobileSensitiveMethod = mobileSensitiveMethod;
    }

    public String getMobileSensitiveAppCode() {
        return mobileSensitiveAppCode;
    }

    public void setMobileSensitiveAppCode(String mobileSensitiveAppCode) {
        this.mobileSensitiveAppCode = mobileSensitiveAppCode;
    }

    public String getBankCardNoSensitiveMethod() {
        return bankCardNoSensitiveMethod;
    }

    public void setBankCardNoSensitiveMethod(String bankCardNoSensitiveMethod) {
        this.bankCardNoSensitiveMethod = bankCardNoSensitiveMethod;
    }

    public String getBankCardNoSensitiveAppCode() {
        return bankCardNoSensitiveAppCode;
    }

    public void setBankCardNoSensitiveAppCode(String bankCardNoSensitiveAppCode) {
        this.bankCardNoSensitiveAppCode = bankCardNoSensitiveAppCode;
    }

    /**
     * 初始化Http服务端配置
     *
     * @throws Exception
     */
    public void initHttpConfig() throws Exception {
        InputStream is = HttpServerConfig.class.getClassLoader().getResourceAsStream("httpserver.properties");
        Properties pro = new Properties();
        pro.load(is);
        this.port = Integer.parseInt(pro.getProperty("httpserver.port"));
        this.ssl = Boolean.parseBoolean(pro.getProperty("httpserver.ssl"));
        this.server_need_client_auth = Boolean.parseBoolean(pro.getProperty("httpserver.server_need_client_auth"));
        this.supportkeepalive = Boolean.parseBoolean(pro.getProperty("httpserver.supportkeepalive"));
        this.zookeeperurl = pro.getProperty("httpserver.zookeeper");
        this.sslPassword = pro.getProperty("httpserver.sslpassword");
        this.sslPath = pro.getProperty("httpserver.sslpath");
        this.jdbcDriverclass = pro.getProperty("jdbc.driverClass");
        this.jdbcPassword = pro.getProperty("jdbc.password");
        this.jdbcUrl = pro.getProperty("jdbc.url");
        this.jdbcUsername = pro.getProperty("jdbc.username");
        this.aesKey=pro.getProperty("aes.key");
        this.idCardNoSensitiveAppCode=pro.getProperty("idcardno.senstive.appcode");
        this.idCardNoSensitiveMethod=pro.getProperty("idcardno.sensitive.method");
        this.mobileSensitiveAppCode=pro.getProperty("mobile.senstive.appcode");
        this.mobileSensitiveMethod=pro.getProperty("mobile.sensitive.method");
        this.bankCardNoSensitiveAppCode=pro.getProperty("bankcardno.senstive.appcode");
        this.bankCardNoSensitiveMethod=pro.getProperty("bankcardno.sensitive.method");
    }

}
